package com.xiangxiangjd.kj.papersstar.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import com.xiangxiangjd.kj.papersstar.bean.result.ResultPage;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import com.xiangxiangjd.kj.papersstar.service.TopicService;
import com.xiangxiangjd.kj.papersstar.bean.Topic;
import com.xiangxiangjd.kj.papersstar.controller.model.ApiResultModel;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 肖守凯
 * @since 2021-01-21
 */
@Controller
@RequestMapping("/papersstar/topic")
public class TopicController extends BaseController{




     /** 主页面 */
    @RequestMapping("admin/main.html")
    public String main(){
       return  "Topic/TopicMain";
    }
    /** 添加页面跳转
     * @return 返回页面
     */
    @RequestMapping(value = "admin/addTopicHtml")
    public String addTopicHtml( ){
             return "Topic/TopicAdd";
    }
    /** 编辑页面跳转
     * @param  id  前端传进的参数
     * @return 返回页面
     */
    @RequestMapping(value = "admin/editTopicHtml")
    public String editTopicHtml(String id ,Model model ){

        System.out.println("id:"+id);

           model.addAttribute("topic",topicService.selectTopicByIdTopic(id));



             return "Topic/TopicEdit";
    }

    /** 查看页面跳转
     * @param  id  前端传进的参数
     * @return 返回页面
     */
    @RequestMapping(value = "admin/showTopicHtml")
    public String showTopicHtml(String id ,Model model ){

        System.out.println("id:"+id);
           model.addAttribute("topic",topicService.selectTopicByIdTopic(id));
             return "Topic/TopicShow";
    }


    /** 分页查询Topic
     * @param page  页码
     * @param limit  查几条
     * @param topic  前端传进的参数
     * @return 返回统一分页信息
     */
    @RequestMapping(value = "admin/findTopicByPage")
    @ResponseBody
    public ResultPage findTopicByPage(Integer page, Integer limit,Topic topic){
             return topicService.findTopicByPage(page,limit,topic);
    }

    /** 添加Topic
     * @param topic  前端传进的参数
     * @return 返回统一信息
     */
    @RequestMapping(value = "admin/addTopic")
    @ResponseBody
    public ApiResultModel saveTopic(Topic topic  ){
             return topicService.addTopic(topic);
    }

    /** 编辑Topic
     * @param topic  前端传进的参数
     * @return 返回统一信息
     */
    @RequestMapping(value = "admin/editTopic")
    @ResponseBody
    public ApiResultModel editTopic(Topic topic  ){
             return topicService.editTopic(topic);
    }



    /** 删除一条Topic
     * @param ids  前端传进的ID
     * @return 返回统一信息
     */
    @RequestMapping(value = "admin/delTopic")
    @ResponseBody
    public ApiResultModel delTopics(@RequestParam("datas[]") ArrayList ids){
             return topicService.delTopics(ids);
    }


}
